package com.chinaisafe.user.vo.response;

import com.chinaisafe.user.entity.SysApp;
import com.chinaisafe.user.entity.SysMenu;
import com.chinaisafe.user.entity.SysModule;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * SysMenuRespVO
 * Description：菜单(资源)响应值对象
 *
 * @author tby
 * @date  2024-07-11 17:32:41
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Schema(name = "SysMenuRespVO", description = "菜单(资源)响应值对象")
public class SysMenuRespVO implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "主键id")
    private Long id;

    @Schema(description = "乐观锁版本")
    private Integer version;

    @Schema(description = "系统资源模块_id")
    private Long sysModuleId;

    @Schema(description = "名称")
    private String title;

    @Schema(description = "所属应用id")
    private Long sysAppId;

    @Schema(description = "是否缓存路由")
    private Boolean keepAlive;

    @Schema(description = "是否为常量路由")
    private Boolean constant;

    @Schema(description = "编码")
    private String name;

    @Schema(description = "父级id")
    private Long parentId;

    @Schema(description = "外部链接")
    private String href;

    @Schema(description = "路由地址")
    private String path;

    @Schema(description = "组件")
    private String component;

    @Schema(description = "是否外链")
    private Boolean frame;

    @Schema(description = "菜单类型")
    private String type;

    @Schema(description = "显示顺序")
    private Integer seq;

    @Schema(description = "激活菜单")
    private String activeMenu;

    @Schema(description = "是否显示")
    private Boolean hideInMenu;

    @Schema(description = "是否固定标签页")
    private Boolean fixedIndexInTab;

    @Schema(description = "是否多标签页")
    private Boolean multiTab;

    @Schema(description = "菜单图标")
    private String icon;

    @Schema(description = "请求参数")
    private String query;

    @Schema(description = "是否启用")
    private Boolean enable;

    @Schema(description = "模块名称")
    private String moduleName;

    @Schema(description = "应用名称")
    private String appName;

    @Schema(description = "是否有权限")
    private Boolean hasAuth;

    private List<SysMenuRespVO> children;


    /**
     * 将实体类转换为响应值对象
     *
     * @param entity    实体对象
     * @param sysApp 应用
     * @param sysModule 模块
     * @return SysMenuRespVO 响应值对象
     * @author tby
     * @date 2024-07-11 17:32:41
     */
    public static SysMenuRespVO convertFromEntity(SysMenu entity, SysApp sysApp, SysModule sysModule) {
        SysMenuRespVO respVO = new SysMenuRespVO();
        respVO.id = entity.getId();
        respVO.version = entity.getVersion();
        // 给对应的字段赋值 可根据实际业务删减
        respVO.sysModuleId = entity.getSysModuleId();
        respVO.title = entity.getTitle();
        respVO.sysAppId = entity.getSysAppId();
        respVO.keepAlive = entity.getKeepAlive();
        respVO.constant = entity.getConstant();
        respVO.name = entity.getName();
        respVO.parentId = entity.getParentId();
        respVO.href = entity.getHref();
        respVO.path = entity.getPath();
        respVO.component = entity.getComponent();
        respVO.frame = entity.getFrame();
        respVO.type = entity.getType();
        respVO.seq = entity.getSeq();
        respVO.activeMenu = entity.getActiveMenu();
        respVO.hideInMenu = entity.getHideInMenu();
        respVO.fixedIndexInTab = entity.getFixedIndexInTab();
        respVO.multiTab = entity.getMultiTab();
        respVO.icon = entity.getIcon();
        respVO.query = entity.getQuery();
        respVO.enable = entity.getEnable();
        respVO.moduleName = sysModule == null ? "" : sysModule.getName();
        respVO.appName = sysApp == null ? "" : sysApp.getName();
        return respVO;
    }
}
